package com.app.service.impl;


import com.app.mapper.ExpertMapper;
import com.app.mapper.IncubatorsMapper;
import com.app.model.ExpertModel;
import com.app.model.IncubatorsModel;
import com.app.service.ExpertService;
import com.app.service.IncubatorsService;
import com.app.util.StringTool;
import com.app.vo.ExpertVo;
import com.app.vo.IncubatorsVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @Description:专家
 * @Author: N
 * @Date: 2022年11月24日 10点29分
 */
@Service
public class IncubatorsServiceImpl implements IncubatorsService {

    @Autowired
    IncubatorsMapper incubatorsMapper;


    @Override
    public List<IncubatorsModel> getListByModel(IncubatorsModel model) {
        QueryWrapper<IncubatorsModel> queryWrapper = new QueryWrapper<>();
        if(model!=null)
        {
            if(StringTool.isNotEmpty(model.getName()))
            {
                queryWrapper.like("name",model.getName());
            }
            if(model.getBaseId()!=null&&model.getBaseId()>0)
            {
                queryWrapper.eq("base_id",model.getBaseId());
            }
        }
        queryWrapper.orderByDesc("crt_time");
        return incubatorsMapper.selectList(queryWrapper);
    }

    @Override
    public IncubatorsVo getPageByModel(IncubatorsModel model) {
        QueryWrapper<IncubatorsModel> queryWrapper = new QueryWrapper<>();
        if (model.getBaseId()!=null&&model.getBaseId()>0) {
            queryWrapper.like("base_id", model.getBaseId());
        }
        if (StringTool.isNotEmpty(model.getName())) {
            queryWrapper.like("name", model.getName());
        }
        Page<IncubatorsModel> pages = new Page<>();
        pages.setCurrent(model.getPage());
        pages.setSize(model.getLimit());
        Page<IncubatorsModel> page = incubatorsMapper.selectPage(pages, queryWrapper);
        if (page == null) {
            return null;
        } else {
            IncubatorsVo vo = new IncubatorsVo();
            vo.setList(page.getRecords());
            vo.setCount((int)page.getTotal());
            return vo;
        }
    }

    @Override
    public IncubatorsModel getModelById(Integer id) {
        return incubatorsMapper.selectById(id);
    }

    @Override
    public int insert(IncubatorsModel model) {
        return incubatorsMapper.insert(model);
    }

    @Override
    public void update(IncubatorsModel model) {
        incubatorsMapper.updateById(model);
    }

    @Override
    public void delete(Integer id) {
        incubatorsMapper.deleteById(id);
    }
}
